﻿
using FileData.Currency;
using FileData.Utils.Currency;
using FileData.Utils.Currency.FileUtils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileData.DataUtils.ViewUtils
{
    class BaiduDriverTool
    {
        static CWebclient LocalWebClient = InitClient();

        private static CWebclient InitClient()
        {
            CWebclient cWebclient = new CWebclient();
            cWebclient.GetHtml("https://pan.baidu.com/s/1i4SFOwP");
            return cWebclient;
        }
        public void Floder(string FloderPath) {
            foreach (var item in new FloderNameHelper().GetFullFileNameList(FloderPath))
            {
                Console.WriteLine(item);
                new ThreadSleep().SetClock(100, 300);
                SingleFile(item);
            }
        }

        public void SingleFile(string FilePath)
        {
            string Content = FileHelper.ReadAllText(FilePath);
            if (Content.IndexOf("baidu.com") < 0)
            {
                Console.WriteLine("不含百度盘，跳过");
                SaveTipFile(FilePath, Content, "不含百度盘");
                return;
            }
            foreach (string Line in HtmlHelper.GetLinkVlaueList(Content, "//a"))
            {
                Console.WriteLine(Line);
                if (Content.IndexOf("baidu.com") < 0)
                {
                    continue;
                }
                string Shtml = LocalWebClient.GetHtml(Line);

                if (Shtml.IndexOf("啊哦") > 0) {
                    Console.WriteLine("链接失效");
                    SaveTipFile(FilePath, Content, "网盘失效");
                    continue;
                }
                SaveTipFile(FilePath, Content, "网盘有效");
            }
        }

        private static void SaveTipFile(string FilePath, string Content,string Tip)
        {
            String NewFilePath = new FileNameHelper().CreateFileNameWithChlidFloder(FilePath, Tip);
            FileHelper.WriteUTF8Text(NewFilePath, Content);
        }
    }
}
